package com.example.usermanagement.validation;

import com.example.usermanagement.anno.State;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

public class StateValidation implements ConstraintValidator<State, String> {

    /**
     *
     * @param value 将来要检验的数据
     * @param context   context in which the constraint is evaluated
     * @return  如果返回false，则验证不通过，如果返回true，则验证通过
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        //提供校验规则
        if (value == null) {
            return false;
        }
        if (value.equals("ACTIVE") || value.equals("LOST") || value.equals("INACTIVE")) {
            return true;
        }
        return false;
    }
}
